from django.urls import path, re_path
from rest_framework.routers import DefaultRouter
from books import views
from rest_framework_jwt.views import obtain_jwt_token

urlpatterns = [
    path('books/book/', views.BookViewSet.as_view({'get': 'list', 'post': 'create'})),
    re_path(r'books/book/(?P<pk>\d+)/$', views.BookViewSet.as_view({'delete': 'destroy'})),
    path('books/banner/', views.BannerViewSet.as_view({'get': 'list'})),
    path('books/malluser/', views.MallUserViewSet.as_view({'get': 'list', 'post': 'create'})),
    path('books/useraddress/', views.UserAddressViewSet.as_view({'get': 'list' , 'post': 'create'})),
    re_path('books/useraddress/(?P<pk>\d+)/$', views.UserAddressViewSet.as_view({'delete': 'destroy', 'put': 'update', 'get': 'retrieve'})),
    path('books/goodsinfo/', views.GoodsInfoViewSet.as_view({'get': 'list'})),
    path('books/goodscategory/', views.GoodsCategoryViewSet.as_view({'get': 'list'})),
    path('books/shoppingcart/',views.ShoppingCartViewSet.as_view({'get': 'list', 'post': 'create'})),
    re_path(r'books/shoppingcart/(?P<pk>\d+)/$', views.ShoppingCartViewSet.as_view({'delete': 'destroy', 'put': 'update', 'get': 'retrieve'})),
    path('books/mallorder/', views.MallOrderViewSet.as_view({'get': 'list', 'post': 'create'})),
    re_path(r'books/mallorder/(?P<pk>\d+)/$', views.MallOrderViewSet.as_view({'delete': 'destroy', 'put': 'update', 'get': 'retrieve'})),
    path('books/orderitem/', views.OrderItemViewSet.as_view({'get': 'list', 'post': 'create'})),
    path('books/orderaddress/', views.OrderAddressViewSet.as_view({'get': 'list', 'post': 'create'})),
    path('books/mallcomment/', views.MallCommentViewSet.as_view({'get': 'list'})),
    path('books/gridimg/', views.GridImgViewSet.as_view({'get': 'list'})),
    # path('books/login/', views.LoginViewSet.as_view()),
    # path('books/order/', views.OrderViewSet.as_view()),
    path('books/login/', views.LoginViewSet.as_view()),
    path('books/order/', views.OrderViewSet.as_view()),
    # path('books/login/', obtain_jwt_token),
]

# 1.创建路由对象
router = DefaultRouter()  # 括号不要忘了 ，不然执行不了

# 2.注册视图集
router.register(r"books", views.BookViewSet, basename='books')

urlpatterns += router.urls

# 3.输出结果
print(router.urls)
